package org.jiucai.app.admin.helper;

import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.jiucai.app.admin.data.AdminConstant;
import org.jiucai.appframework.base.spring.helper.SpringHelper;
import org.jiucai.appframework.common.util.LogUtil;
import org.jiucai.appframework.common.util.Logs;

public class AdminHelper extends SpringHelper {
	
	protected static Logs log = LogUtil.getLog(AdminHelper.class);
	
	/**
	 * 解析请求参数
	 * 
	 * @param request
	 * @return
	 */
	public static synchronized Map<String, Object> parseRequest(
			HttpServletRequest request) {
		Map<String, Object> param = new HashMap<String, Object>();
		Object reqAttr = null;
		String attrName, paraName;

		@SuppressWarnings("rawtypes")
		Enumeration attrs = request.getAttributeNames();

		while (attrs.hasMoreElements()) {
			attrName = (String) attrs.nextElement();

			if (null != attrName && attrName.startsWith(AdminConstant.REQ_PREFIX)) {

				paraName = attrName.substring(
						attrName.indexOf(AdminConstant.REQ_PREFIX)
								+ AdminConstant.REQ_PREFIX.length(),
						attrName.length());

				reqAttr = request.getAttribute(attrName);

				param.put(paraName, reqAttr);

			}
		}
		return param;

	}
	
}
